/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package generadorva;

import ec.util.MersenneTwisterFast;

/**
 *
 * @author USUARIO
 */
public class BoxMuller {

    private double media;
    private double varianza;
    private double x;
    private double y;

    public BoxMuller(double media, double varianza) {
        this.media = media;
        this.varianza = varianza;
    }
    
    public double generate(MersenneTwisterFast prng){
        double u1, u2;
        u1 = prng.nextDouble();
        u2 = prng.nextDouble();
        double theta = u1 * 2 * Math.PI;
        double r = Math.sqrt(-2 * Math.log(u2));
        x = r * Math.cos(theta) * Math.sqrt(varianza) + media;
        y = r * Math.sin(theta) * Math.sqrt(varianza) + media;
        return x;
    }

    public double getMedia() {
        return media;
    }

    public double getVarianza() {
        return varianza;
    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }


}
